<?php
/**
 * @apiVersion 1.0.0
 * @api {POST} /wechat/User/getUserInfo 004获取用户信息接口OK
 * @apiDescription 获取用户信息接口
 * @apiGroup Pub
 * @apiPermission 公众号

 * @apiSuccess  {Int} code 状态
 * @apiSuccess  {Object} data 元数据
 * @apiSuccess  {String} msg 错误说明
 * @apiSuccessExample {json} 响应示例:
{
    "code": 1,
    "msg": "登录成功",
    "data": {
        "userID": 237,  //用户id
        "photo": null,  //头像
        "mobile": "15573179664",  //手机号
        "nickname": null,  //昵称
        "sex": 0,  //性别：
        "trueName": "张三",  //真实姓名
        "card": "273273723723",  //身份证号码
        "updataTime": 1620157828,
        "addTime": 1620157741,  //注册时间
        "status": 1,      //状态： 1正常 0禁用
        "serialNumber": null,
        "appType": null,
        "mobileType": null,
        "password": null,
        "payPassword": null,
        "agent": null,
        "clientIP": "3740760482",
        "location": null,
        "judge": 0,
        "version": null,
        "latitude": null,
        "longitude": null,
        "apliayUsername": null, //支付宝账号
        "apliayPassword": null, //支付宝密码
        "apliayPayPassword": null,  //支付宝支付密码
        "wechatUsername": null, //微信账号
        "wechatPassword": null, //微信密码
        "wechatPayPassword": null,  //微信支付密码
        "depositUsername": null,    //提现账号
        "depositType": null,    //提现类型： 1支付宝 2微信
        "platformID": 0,    //平台id
        "statusCheck": -1,
        "xrkCode": null,    //葵码
        "checkTime": null,
        "checkManger": null,
        "cMobile": "",
        "depositRealname": "",
        "openID": null, //微信openid
        "unionID": null,    //开发平台id
        "loginTimes": 3,
        "lastLoginTime": 1620157828
    }
}

 * //操作未成功提示信息
 * {
 *      "code":0,
 *      "msg" :"错误说明"
 * }
 */


/**
 * @apiVersion 1.0.0
 * @api {POST} /wechat/Abnormal/getConfigList 006异常原因列表OK
 * @apiDescription 异常原因列表
 * @apiGroup Abnormal
 * @apiPermission 公众号


 * @apiSuccess  {Int} code 状态
 * @apiSuccess  {Object} data 元数据
 * @apiSuccess  {String} msg 错误说明
 * @apiSuccessExample {json} 响应示例:
{
    "code" : 1,
    "list" :{
        "name": "异常原因名称",
        "id": "100"
 }
}

 * //操作未成功提示信息
 * {
 *      "code":0,
 *      "msg" :"错误说明"
 * }
 */

/**
 * @apiVersion 1.0.0
 * @api {POST} /wechat/Abnormal/add 007异常收集提交OK
 * @apiDescription 异常收集提交
 * @apiGroup Abnormal
 * @apiPermission 公众号
 * @apiParam {int} type 异常原因id
 * @apiParam {string} content 备注
 * @apiParam {string} cMobile 常用联系方式
 * @apiParam {string} img 截图
 * @apiParamExample {json} 请求示例:
 * {
 *      "type": 1,
 *      "content": "备注",
 *      "cMobile": "常用联系方式",
 *      "img": "http://a.test.com/1.png",
 * }
 * @apiSuccess  {Int} code 状态
 * @apiSuccess  {Object} data 元数据
 * @apiSuccess  {String} msg 错误说明
 * @apiSuccessExample {json} 响应示例:
{

}

 * //操作未成功提示信息
 * {
 *      "code":0,
 *      "msg" :"错误说明"
 * }
 */

namespace app\wechat\controller;


use app\model\FreshAdminAuthGroupAccess;
use app\model\FreshAdminUser;

use app\model\FreshAdminUserData;
use app\util\ReturnCode;
use app\util\Tools;
use think\Db;

class Abnormal extends Base {


    /**
     * 异常原因列表
     */
    public function getConfigList() {

        $list = Db::name('abnormal_config')->select();
        return $this->buildSuccess($list, '操作成功');
    }

    public function add(){
        $postData = $this->request->post();
        if(!isset($postData['type']))  return $this->buildFailed(ReturnCode::INVALID,'异常原因不能为空');
        if(!isset($postData['content']))  return $this->buildFailed(ReturnCode::INVALID,'备注不能为空');
        if(!isset($postData['cMobile']))  return $this->buildFailed(ReturnCode::INVALID,'常用联系方式不能为空');
        if(!isset($postData['img']))  return $this->buildFailed(ReturnCode::INVALID,'截图不能为空');
        $user = Db::name('user')->where('userID', $this->userInfo['userID'])->find();
        $add = [
            'userID' => $user['userID'],
            'platformID' => $user['platformID'],
            'xrkCode' => $user['xrkCode'],
            'realname' => $user['realname'],
            'mobile' => $user['mobile'],
            'type' => $postData['type'],
            'content' => $postData['content'],
            'addTime' => time(),
            'cMobile' => $postData['cMobile'],
            'img' => $postData['img'],
        ];
        $flag = Db::name('abnormal_record')->insertGetId($add);
        if($flag){
            return $this->buildSuccess([], '操作成功');
        }else{
            return $this->buildFailed(ReturnCode::INVALID,'提交失败');
        }
    }


}
